package main

import (
	"gogo"
)

// 验证用户名和密码的函数
func validateUser(username, password string) bool {
	// 使用安全比较防止时序攻击
	return gogo.SecureCompare(username, "admin") && gogo.SecureCompare(password, "password")
}

func main() {
	// 注册一个公开的路由
	gogo.GET("/", func(ctx *gogo.HTTPContext) {
		ctx.WriteString("Hello, Public World!")
	})

	// 注册一个受保护的GET路由
	gogo.GET_PRE("/protected", gogo.BasicAuth(validateUser, "Please enter your username and password"))
	gogo.GET("/protected", func(ctx *gogo.HTTPContext) {
		ctx.WriteString("Hello, Protected World! You have been authenticated.")
	})

	// 启动HTTP服务
	gogo.StartHTTP(3009)
}
